package de.uni.muenster.idw2.adapter;

import java.util.ArrayList;
import java.util.LinkedList;

import android.app.Activity;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;

public class BuildingGalleryAdapter extends BaseAdapter{

	private final ArrayList<String> paths;
	private LinkedList<Drawable> drawables = new LinkedList<Drawable>();
	private final Activity act;

	public BuildingGalleryAdapter(Activity act, ArrayList<String> paths){
		this.act = act;
		this.paths = new ArrayList<String>(paths);
		
		
		
		
	}
	
	public void serImageList(LinkedList<Drawable> drawables){
		this.drawables = drawables;
	}
	
	@Override
	public int getCount() {
		return paths.size() -1;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ImageView i = new ImageView(act);

		if(position < drawables.size() && drawables.get(position) != null){
	        i.setImageDrawable(drawables.get(position));
	        
	        int hight = drawables.get(position).getMinimumHeight();
	        int width = drawables.get(position).getMinimumWidth();
	        
	        double diff = width/((double)hight);
	        
	        Display display = act.getWindowManager().getDefaultDisplay(); 
	        int displayWidth =(int) (display.getWidth() / 4);
	        
	        i.setLayoutParams(new Gallery.LayoutParams((int)(displayWidth * diff), displayWidth));
	        i.setScaleType(ImageView.ScaleType.FIT_XY);
		}
		else{
			Display display = act.getWindowManager().getDefaultDisplay(); 
	        int displayWidth =(int) (display.getWidth() / 4);
	        
	        i.setLayoutParams(new Gallery.LayoutParams((int)(displayWidth * 1.3), displayWidth));
	        i.setBackgroundColor(Color.argb(100, 130, 130, 130));
	        i.setPadding(8, 8, 8, 8);
	        i.setScaleType(ImageView.ScaleType.FIT_XY);
		}
        
        return i;
		
	}
	
	public void removeOneObject(){
		if(paths.size() > 0){
			paths.remove(0);
		}
	}
}
